package com.yanqu.road.server.logic.activity.condition.zhenhuan;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;
import com.yanqu.road.utils.date.DateHelper;

import java.math.BigInteger;

public class ZhenHuanThirdProcessRankCondition extends BaseNewRankActivityCondition {
    public ZhenHuanThirdProcessRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        long score = (long) object;
        if (getValue().longValue() >= score) {
            return;
        }
        setValue(BigInteger.valueOf(score));
        // 跨服更新就好了
        // rankChange();
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.ZhenHuanThirdProcessRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.ZhenHuanThirdProcessRank.getValue(), handle);
    }

    @Override
    public boolean canChange(ActivityInfo activityInfo){
        long currentSecond = DateHelper.getCurrentTime() / 1000;
        if (currentSecond < activityInfo.getBeginTime() || currentSecond > activityInfo.getEndTime() + 5) {
            return false;
        }
        return true;
    }
}
